
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Milton
 */
public class VentanaVenta extends javax.swing.JFrame implements ActionListener{
    private DefaultTableModel modelo;
    /**
     * Creates new form VentanaVenta
     */
    public VentanaVenta() {
        initComponents();               
        panelTotalizado.setVisible(false);
        setControlador();
        modelo = new DefaultTableModel(
            null,
            new String [] {
                "Cod Producto", "Nombre","Cantidad","Precio Unitario","Valor Descuento", "Total"}
        );        
       
        
        tablaProductos.setModel(modelo);
        
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    
    public void setControlador(){
        botonAdicionar.addActionListener(this);
        botonPagar.addActionListener(this);
        botonRegistrar.addActionListener(this);
        botonTotalizar.addActionListener(this);
        
    }
    
    public DefaultTableModel getModelo() {
        return modelo;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelNroVenta = new javax.swing.JLabel();
        labelTitulo = new javax.swing.JLabel();
        textNroVenta = new javax.swing.JTextField();
        labelProducto = new javax.swing.JLabel();
        textProducto = new javax.swing.JTextField();
        labelCantidad = new javax.swing.JLabel();
        spinnerCantidad = new javax.swing.JSpinner();
        botonAdicionar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaProductos = new javax.swing.JTable();
        labelDocCliente = new javax.swing.JLabel();
        textDocCliente = new javax.swing.JTextField();
        labelPregunta = new javax.swing.JLabel();
        botonRegistrar = new javax.swing.JButton();
        botonTotalizar = new javax.swing.JButton();
        panelTotalizado = new javax.swing.JPanel();
        labelSubtotal = new javax.swing.JLabel();
        textSubtotal = new javax.swing.JTextField();
        labelIVA = new javax.swing.JLabel();
        textIVA = new javax.swing.JTextField();
        labelDescuento = new javax.swing.JLabel();
        textDescuento = new javax.swing.JTextField();
        labelTotal = new javax.swing.JLabel();
        textTotal = new javax.swing.JTextField();
        botonPagar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        labelNroVenta.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelNroVenta.setForeground(new java.awt.Color(51, 102, 255));
        labelNroVenta.setText("# Venta:");

        labelTitulo.setFont(new java.awt.Font("Consolas", 1, 18)); // NOI18N
        labelTitulo.setForeground(new java.awt.Color(0, 51, 102));
        labelTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelTitulo.setText("REALIZAR VENTA");

        textNroVenta.setEditable(false);
        textNroVenta.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N

        labelProducto.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelProducto.setForeground(new java.awt.Color(51, 102, 255));
        labelProducto.setText("Cod Producto:");

        textProducto.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N

        labelCantidad.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelCantidad.setForeground(new java.awt.Color(51, 102, 255));
        labelCantidad.setText("Cantidad:");

        spinnerCantidad.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        spinnerCantidad.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1)));

        botonAdicionar.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
        botonAdicionar.setText("Adicionar");

        tablaProductos.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        tablaProductos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tablaProductos);

        labelDocCliente.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelDocCliente.setForeground(new java.awt.Color(51, 102, 255));
        labelDocCliente.setText("Doc ID Cliente:");

        textDocCliente.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N

        labelPregunta.setFont(new java.awt.Font("Kalinga", 2, 10)); // NOI18N
        labelPregunta.setForeground(new java.awt.Color(51, 102, 255));
        labelPregunta.setText("¿No se encuentra registrado el cliente?");

        botonRegistrar.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
        botonRegistrar.setText("Registrar Cliente");

        botonTotalizar.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
        botonTotalizar.setText("Totalizar >");

        labelSubtotal.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelSubtotal.setForeground(new java.awt.Color(51, 102, 255));
        labelSubtotal.setText("Subtotal:");

        textSubtotal.setEditable(false);
        textSubtotal.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N

        labelIVA.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelIVA.setForeground(new java.awt.Color(51, 102, 255));
        labelIVA.setText("IVA:");

        textIVA.setEditable(false);
        textIVA.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N

        labelDescuento.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelDescuento.setForeground(new java.awt.Color(51, 102, 255));
        labelDescuento.setText("Descuento:");

        textDescuento.setEditable(false);
        textDescuento.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N

        labelTotal.setFont(new java.awt.Font("Kalinga", 0, 14)); // NOI18N
        labelTotal.setForeground(new java.awt.Color(51, 102, 255));
        labelTotal.setText("Total:");

        textTotal.setEditable(false);
        textTotal.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N

        botonPagar.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
        botonPagar.setText("Pagar");

        javax.swing.GroupLayout panelTotalizadoLayout = new javax.swing.GroupLayout(panelTotalizado);
        panelTotalizado.setLayout(panelTotalizadoLayout);
        panelTotalizadoLayout.setHorizontalGroup(
            panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTotalizadoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelTotalizadoLayout.createSequentialGroup()
                        .addGroup(panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelDescuento)
                            .addComponent(labelIVA)
                            .addComponent(labelSubtotal))
                        .addGap(27, 27, 27)
                        .addGroup(panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textSubtotal)
                            .addComponent(textIVA)
                            .addComponent(textDescuento, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)))
                    .addGroup(panelTotalizadoLayout.createSequentialGroup()
                        .addComponent(labelTotal)
                        .addGap(68, 68, 68)
                        .addComponent(textTotal, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelTotalizadoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonPagar)
                .addGap(86, 86, 86))
        );
        panelTotalizadoLayout.setVerticalGroup(
            panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelTotalizadoLayout.createSequentialGroup()
                .addGroup(panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelSubtotal)
                    .addComponent(textSubtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelIVA)
                    .addComponent(textIVA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDescuento)
                    .addComponent(textDescuento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelTotalizadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelTotal)
                    .addComponent(textTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botonPagar)
                .addGap(0, 19, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(labelPregunta)
                .addGap(93, 93, 93))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGap(188, 188, 188)
                            .addComponent(labelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(labelCantidad)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(spinnerCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(labelNroVenta)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(textNroVenta, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGap(125, 125, 125)
                            .addComponent(labelProducto)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(textProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(221, 221, 221)
                        .addComponent(botonAdicionar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(104, 104, 104)
                        .addComponent(botonTotalizar)
                        .addGap(26, 26, 26)
                        .addComponent(panelTotalizado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(labelDocCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(textDocCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botonRegistrar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 504, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo)
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelNroVenta)
                    .addComponent(textNroVenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelProducto)
                    .addComponent(textProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCantidad)
                    .addComponent(spinnerCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addComponent(botonAdicionar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDocCliente)
                    .addComponent(textDocCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonRegistrar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelPregunta)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botonTotalizar)
                    .addComponent(panelTotalizado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAdicionar;
    private javax.swing.JButton botonPagar;
    private javax.swing.JButton botonRegistrar;
    private javax.swing.JButton botonTotalizar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelCantidad;
    private javax.swing.JLabel labelDescuento;
    private javax.swing.JLabel labelDocCliente;
    private javax.swing.JLabel labelIVA;
    private javax.swing.JLabel labelNroVenta;
    private javax.swing.JLabel labelPregunta;
    private javax.swing.JLabel labelProducto;
    private javax.swing.JLabel labelSubtotal;
    private javax.swing.JLabel labelTitulo;
    private javax.swing.JLabel labelTotal;
    private javax.swing.JPanel panelTotalizado;
    private javax.swing.JSpinner spinnerCantidad;
    private javax.swing.JTable tablaProductos;
    private javax.swing.JTextField textDescuento;
    private javax.swing.JTextField textDocCliente;
    private javax.swing.JTextField textIVA;
    private javax.swing.JTextField textNroVenta;
    private javax.swing.JTextField textProducto;
    private javax.swing.JTextField textSubtotal;
    private javax.swing.JTextField textTotal;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent ae) {
        
        if(ae.getActionCommand().equals("Registrar Cliente")){
            VentanaAdminCliente ventanaCrearCliente = new VentanaAdminCliente("Crear");
            ventanaCrearCliente.setVisible(true);
            ventanaCrearCliente.setLocationRelativeTo(this);
        }
        
        if(ae.getActionCommand().equals("Adicionar")){
            JOptionPane.showMessageDialog(null, "Implementame! D:");
        }
        
        if(ae.getActionCommand().equals("Totalizar >")){
            panelTotalizado.setVisible(true);
        }
        
        if(ae.getActionCommand().equals("Pagar")){
            VentanaFraccionPago ventanaPago = new VentanaFraccionPago();
            ventanaPago.setVisible(true);
            ventanaPago.setLocationRelativeTo(this);
            this.dispose();
        }
    }
}
